using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using ViCode_LeVi.Controls.ControlsWin;
using ViCode_LeVi.Controls.BTBData;
using ViCode_LeVi.Controls.Logs;
using ViCode_LeVi.Controls.Charts;
using ViCode_LeVi.Data;

namespace ViCode_LeVi.Controls.Reports
{
    public class ContentSelection
    {
        public bool StrategyFormulation=true;
        public bool BusinessModel=true;
        public bool BusinessModelCommentary=true;
        public bool BusinessField=true;
        public bool BusinessFieldCommentary=true;
        public bool BusinessPlan=true;
        public bool BusinessPlanCommentary=true;
        public bool StatusQuoResultFactors=true;
        public bool PotentialPortfolioChart=true;
        public bool SuccessCommentary=true;
        public bool Actions=true;
        public bool ActionList=true;
        public bool ActionListCommentary=true;
        public bool BankCommentaries=true;
        public bool CommentaryOverView=true;
        public bool FinishCommentary=true;
        public bool Appendix=true;
        public bool SuccessFactors=true;
        public bool EFDefinition=true;
        public bool ImportanceChart=true;
        public bool ImportanceOverView=true;
        public bool ImportanceStatement=true;
        public bool ImportanceCommentary=true;
        public bool QQSAppraisal=true;
        public bool QQSChart=true;
        public bool QQSOverView=true;
        public bool QQSStatement=true;
        public bool QQSCommentary=true;
    }
    public partial class EndReport : DevExpress.XtraReports.UI.XtraReport
    {

        private string m_sTitle = "Titel";
        public EndReport()
        {
            try
            {
                this.InitializeComponent();                
            }
            catch (Exception exception)
            {
                Log.LogException(exception);
            }
        }

        private XRSubreport AddSubReportToBand(Band oDetailBand, int iXPosition, int iYPosition)
        {
            XRSubreport child = null;
            try
            {
                child = new XRSubreport
                {
                    Location = new Point(iXPosition, iYPosition)
                };
                oDetailBand.Controls.Add(child);
            }
            catch (Exception exception)
            {
                Log.LogException(exception);
            }
            return child;
        }

        private Step_BalanceAndOthers BalanceAndOthers
        {
            get { return RootData.Intance.Steps[9].BalanceAndOthers; }
        }

        public bool CreateReport(ContentSelection oContentSelection, System.Collections.Specialized.StringCollection aHiddenElements, ref string rsErr)
        {
            bool flag = true;
            int iNumberOfElements = 0;
            int num2 = 0;
            string str = string.Empty;
            try
            {
                flag = this.SetHeaderFooter(ref rsErr);
                ReportTemplate.ShowExportFilters(this);
                ReportTemplate.CustomizeUI(this);
                if (flag)
                {
                    if (oContentSelection.StrategyFormulation)
                    {
                        if (oContentSelection.BusinessModel)
                        {
                            if (!this.InsertQuestionAnswerSubReport(1, 1, ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            else if (this.DetailReportBusinessModel.Visible)
                            {
                                num2++;
                                this.DetailReportBusinessModel.PageBreak = PageBreak.AfterBand;
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessModel.Visible = false;
                        }
                        if (oContentSelection.BusinessModelCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep1 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep1 != null) && (RootData.Intance.BankCommentStep1 != string.Empty)))
                                {
                                    this.ampelControlBusinessModelCommentary.Result = RootData.Intance.Steps[0].Result;                                    
                                    this.ampelControlBusinessModelCommentary.DisplayStatus = RootData.Intance.BankAmpelStep1;
                                    this.cellBusinessModelCommentary.Text = RootData.Intance.BankCommentStep1;
                                    this.DetailReportBusinessModelCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportBusinessModelCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Business Environment ");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessModelCommentary.Visible = false;
                        }
                        if (oContentSelection.BusinessField)
                        {
                            if (!this.InsertQuestionAnswerSubReport(2, 1, ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            if (!this.InsertQuestionAnswerSubReport(2, 2, ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            if (this.DetailReportMarketSituation.Visible || this.DetailReportEnvironmentFactor.Visible)
                            {
                                this.DetailReportBusinessField.PageBreak = PageBreak.AfterBand;
                                num2++;
                            }
                            else
                            {
                                this.DetailReportBusinessField.Visible = false;
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessField.Visible = false;
                        }
                        if (oContentSelection.BusinessFieldCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep2 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep2 != null) && (RootData.Intance.BankCommentStep2 != string.Empty)))
                                {
                                    this.ampelControlBusinessFieldCommentary.Result = RootData.Intance.Steps[1].Result;
                                    this.cellBusinessFieldCommentary.Text = RootData.Intance.Steps[1].Result.Note;
                                    //this.ampelControlBusinessFieldCommentary.DisplayStatus = RootData.Intance.BankAmpelStep2;
                                    //this.cellBusinessFieldCommentary.Text = RootData.Intance.BankCommentStep2;
                                    this.DetailReportBusinessFieldCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportBusinessFieldCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Business Environment ");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessFieldCommentary.Visible = false;
                        }
                        if (oContentSelection.BusinessPlan)
                        {
                            if (!this.InsertQuestionAnswerSubReport(3, 1, ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            else if (this.DetailReportBusinessPlan.Visible)
                            {
                                this.DetailReportBusinessPlan.PageBreak = PageBreak.AfterBand;
                                num2++;
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessPlan.Visible = false;
                        }
                        if (oContentSelection.BusinessPlanCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep3 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep3 != null) && (RootData.Intance.BankCommentStep3 != string.Empty)))
                                {
                                    this.ampelControlBusinessPlanCommentary.Result = RootData.Intance.Steps[2].Result;
                                    this.cellBusinessPlanCommentary.Text = RootData.Intance.Steps[2].Result.Note;
                                    
                                    //this.ampelControlBusinessPlanCommentary.DisplayStatus = RootData.Intance.BankAmpelStep3;
                                    //this.cellBusinessPlanCommentary.Text = RootData.Intance.BankCommentStep3;
                                    this.DetailReportBusinessPlanCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportBusinessPlanCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Business strategy");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportBusinessPlanCommentary.Visible = false;
                        }
                    }
                    else
                    {
                        this.DetailReportStrategyFormulation.Visible = false;
                    }
                    if (oContentSelection.StatusQuoResultFactors)
                    {
                        if (oContentSelection.PotentialPortfolioChart)
                        {
                            if (!this.InsertPotentialPortfolioSubReport(ref iNumberOfElements, ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            if (this.DetailReportPotentialPortfolioChart.Visible)
                            {
                                this.DetailReportPotentialPortfolioChart.PageBreak = PageBreak.AfterBand;
                                num2++;
                            }
                        }
                        else
                        {
                            this.DetailReportPotentialPortfolioChart.Visible = false;
                        }
                        if (oContentSelection.SuccessCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep6 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep6 != null) && (RootData.Intance.BankCommentStep6 != string.Empty)))
                                {
                                    this.ampelControlSuccessCommentary.Result = RootData.Intance.Steps[5].Result;
                                    this.cellSuccessCommentary.Text = RootData.Intance.Steps[5].Result.Note;
                                    
                                    //this.ampelControlSuccessCommentary.DisplayStatus = RootData.Intance.BankAmpelStep6;
                                    //this.cellSuccessCommentary.Text = RootData.Intance.BankCommentStep6;
                                    this.DetailReportSuccessCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportSuccessCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Success Factors");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportSuccessCommentary.Visible = false;
                        }
                    }
                    else
                    {
                        this.DetailReportStatusQuoResultFactors.Visible = false;
                    }
                    if (oContentSelection.Actions)
                    {
                        if (oContentSelection.ActionList)
                        {
                            if (!this.InsertActionSubReport(ref aHiddenElements, ref rsErr))
                            {
                                str = str + "\n\r" + rsErr;
                            }
                            if (this.DetailReportActionList.Visible)
                            {
                                this.DetailReportActionList.PageBreak = PageBreak.AfterBand;
                                num2++;
                            }
                        }
                        else
                        {
                            this.DetailReportActionList.Visible = false;
                        }
                        if (oContentSelection.ActionListCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep7 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep7 != null) && (RootData.Intance.BankCommentStep7 != string.Empty)))
                                {
                                    this.ampelControlActionListCommentary.Result = RootData.Intance.Steps[6].Result;
                                    this.cellActionListCommentary.Text = RootData.Intance.Steps[6].Result.Note;
                                 
                                    //this.ampelControlActionListCommentary.DisplayStatus = RootData.Intance.BankAmpelStep7;
                                    //this.cellActionListCommentary.Text = RootData.Intance.BankCommentStep7;
                                    this.DetailReportActionListCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportActionListCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Measures");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportActionListCommentary.Visible = false;
                        }
                    }
                    else
                    {
                        this.DetailReportActions.Visible = false;
                    }
                    if (oContentSelection.BankCommentaries)
                    {
                        if (oContentSelection.CommentaryOverView)
                        {
                            int num3 = 0;
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep1 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep1 != null) && (RootData.Intance.BankCommentStep1 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView1.Result = RootData.Intance.Steps[0].Result;
                                    this.cellCommentaryOverView1.Text = RootData.Intance.Steps[0].Result.Note;
                                 
                                    //this.ampelControlCommentaryOverView1.DisplayStatus = RootData.Intance.BankAmpelStep1;
                                    //this.cellCommentaryOverView1.Text = RootData.Intance.BankCommentStep1;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary1.Visible = false;
                                    this.rowCommentary1_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep2 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep2 != null) && (RootData.Intance.BankCommentStep2 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView2.Result = RootData.Intance.Steps[1].Result;
                                    this.cellCommentaryOverView2.Text = RootData.Intance.Steps[1].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView2.DisplayStatus = RootData.Intance.BankAmpelStep2;
                                    //this.cellCommentaryOverView2.Text = RootData.Intance.BankCommentStep2;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary2.Visible = false;
                                    this.rowCommentary2_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep3 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep3 != null) && (RootData.Intance.BankCommentStep3 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView3.Result = RootData.Intance.Steps[2].Result;
                                    this.cellCommentaryOverView3.Text = RootData.Intance.Steps[2].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView3.DisplayStatus = RootData.Intance.BankAmpelStep3;
                                    //this.cellCommentaryOverView3.Text = RootData.Intance.BankCommentStep3;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary3.Visible = false;
                                    this.rowCommentary3_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep4 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep4 != null) && (RootData.Intance.BankCommentStep4 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView4.Result = RootData.Intance.Steps[3].Result;
                                    this.cellCommentaryOverView4.Text = RootData.Intance.Steps[3].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView4.DisplayStatus = RootData.Intance.BankAmpelStep4;
                                    //this.cellCommentaryOverView4.Text = RootData.Intance.BankCommentStep4;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary4.Visible = false;
                                    this.rowCommentary4_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep5 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep5 != null) && (RootData.Intance.BankCommentStep5 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView5.Result = RootData.Intance.Steps[4].Result;
                                    this.cellCommentaryOverView5.Text = RootData.Intance.Steps[4].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView5.DisplayStatus = RootData.Intance.BankAmpelStep5;
                                    //this.cellCommentaryOverView5.Text = RootData.Intance.BankCommentStep5;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary5.Visible = false;
                                    this.rowCommentary5_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep6 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep6 != null) && (RootData.Intance.BankCommentStep6 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView6.Result = RootData.Intance.Steps[5].Result;
                                    this.cellCommentaryOverView6.Text = RootData.Intance.Steps[5].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView6.DisplayStatus = RootData.Intance.BankAmpelStep6;
                                    //this.cellCommentaryOverView6.Text = RootData.Intance.BankCommentStep6;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary6.Visible = false;
                                    this.rowCommentary6_1.Visible = false;
                                }
                                if ((RootData.Intance.BankAmpelStep7 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep7 != null) && (RootData.Intance.BankCommentStep7 != string.Empty)))
                                {
                                    this.ampelControlCommentaryOverView7.Result = RootData.Intance.Steps[6].Result;
                                    this.cellCommentaryOverView7.Text = RootData.Intance.Steps[6].Result.Note;
                          
                                    //this.ampelControlCommentaryOverView7.DisplayStatus = RootData.Intance.BankAmpelStep7;
                                    //this.cellCommentaryOverView7.Text = RootData.Intance.BankCommentStep7;
                                    num3++;
                                }
                                else
                                {
                                    this.rowCommentary7.Visible = false;
                                    this.rowCommentary7_1.Visible = false;
                                }
                            }
                            if (num3 == 0)
                            {
                                this.DetailReportCommentaryOverView.Visible = false;
                                aHiddenElements.Add("Overview Comment");
                            }
                            else
                            {
                                this.DetailReportCommentaryOverView.PageBreak = PageBreak.AfterBand;
                                num2++;
                            }
                        }
                        else
                        {
                            this.DetailReportCommentaryOverView.Visible = false;
                        }
                        if (oContentSelection.FinishCommentary)
                        {
                            if (RootData.Intance != null)
                            {
                                if ((RootData.Intance.BankAmpelStep8 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep8 != null) && (RootData.Intance.BankCommentStep8 != string.Empty)))
                                {
                                    //[7]-> step 8: Step nay la them vao, ko co -> tab cuoi
                                    this.ampelControlFinishCommentary.Result = RootData.Intance.Steps[8].Result;
                                    this.cellFinishCommentary.Text = RootData.Intance.Steps[8].Result.Note;
                          
                                    //this.ampelControlFinishCommentary.DisplayStatus = RootData.Intance.BankAmpelStep8;
                                    //this.cellFinishCommentary.Text = RootData.Intance.BankCommentStep8;
                                    this.DetailReportFinishCommentary.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                else
                                {
                                    this.DetailReportFinishCommentary.Visible = false;
                                    aHiddenElements.Add("Comment Statements");
                                }
                            }
                        }
                        else
                        {
                            this.DetailReportFinishCommentary.Visible = false;
                        }
                    }
                    else
                    {
                        this.DetailReportBankCommentaries.Visible = false;
                    }
                    if (oContentSelection.Appendix)
                    {
                        if (oContentSelection.SuccessFactors)
                        {
                            if (oContentSelection.EFDefinition)
                            {
                                int iCountElements = 0;
                                if (!this.InsertFactorSubReport(FactorType.HK, this.DetailReportEFDefinitionHK, this.DetailEFDefinitionHK, ref iCountElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertFactorSubReport(FactorType.SK, this.DetailReportEFDefinitionSK, this.DetailEFDefinitionSK, ref iCountElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertFactorSubReport(FactorType.BK, this.DetailReportEFDefinitionBK, this.DetailEFDefinitionBK, ref iCountElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (iCountElements == 0)
                                {
                                    aHiddenElements.Add("Definition Success Factors");
                                    this.DetailReportEFDefinition.Visible = false;
                                }
                                else
                                {
                                    this.DetailReportEFDefinition.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportEFDefinition.Visible = false;
                            }
                            if (oContentSelection.ImportanceChart)
                            {
                                if (!this.InsertBarChartImportanceSubReport(ref iNumberOfElements, ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportImportanceChart.Visible)
                                {
                                    this.DetailReportImportanceChart.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportImportanceChart.Visible = false;
                            }
                            if (oContentSelection.ImportanceOverView)
                            {
                                if (!this.InsertImportanceTimeSeriesSubReport(ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportImportanceOverView.Visible)
                                {
                                    this.DetailReportImportanceOverView.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportImportanceOverView.Visible = false;
                            }
                            if (oContentSelection.ImportanceStatement)
                            {
                                int num5 = 0;
                                if (!this.InsertImportanceStatementSubReport(FactorType.HK, this.DetailReportImportanceStatementHK, this.DetailImportanceStatementHK, ref num5, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertImportanceStatementSubReport(FactorType.SK, this.DetailReportImportanceStatementSK, this.DetailImportanceStatementSK, ref num5, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertImportanceStatementSubReport(FactorType.BK, this.DetailReportImportanceStatementBK, this.DetailImportanceStatementBK, ref num5, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (num5 == 0)
                                {
                                    aHiddenElements.Add("Justification Weighting");
                                    this.DetailReportImportanceStatement.Visible = false;
                                }
                                else
                                {
                                    this.DetailReportImportanceStatement.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportImportanceStatement.Visible = false;
                            }
                            if (oContentSelection.ImportanceCommentary)
                            {
                                if (RootData.Intance != null)
                                {
                                    if ((RootData.Intance.BankAmpelStep4 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep4 != null) && (RootData.Intance.BankCommentStep4 != string.Empty)))
                                    {
                                        this.ampelControlImportanceCommentary.DisplayStatus = RootData.Intance.BankAmpelStep4;
                                        this.cellImportanceCommentary.Text = RootData.Intance.BankCommentStep4;
                                        this.DetailReportImportanceCommentary.PageBreak = PageBreak.AfterBand;
                                        num2++;
                                    }
                                    else
                                    {
                                        this.DetailReportImportanceCommentary.Visible = false;
                                        aHiddenElements.Add("Comment Weighting");
                                    }
                                }
                            }
                            else
                            {
                                this.DetailReportImportanceCommentary.Visible = false;
                            }
                        }
                        else
                        {
                            this.DetailReportSuccessFactors.Visible = false;
                        }
                        if (oContentSelection.QQSAppraisal)
                        {
                            if (oContentSelection.QQSChart)
                            {
                                if (!this.InsertBarChartQQSSubReport(FactorType.HK, this.DetailReportQQSChartHK, this.DetailQQSChartHK, ref iNumberOfElements, ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportQQSChartHK.Visible)
                                {
                                    this.DetailReportQQSChartHK.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                if (!this.InsertBarChartQQSSubReport(FactorType.SK, this.DetailReportQQSChartSK, this.DetailQQSChartSK, ref iNumberOfElements, ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportQQSChartSK.Visible)
                                {
                                    this.DetailReportQQSChartSK.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                                if (!this.InsertBarChartQQSSubReport(FactorType.BK, this.DetailReportQQSChartBK, this.DetailQQSChartBK, ref iNumberOfElements, ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportQQSChartBK.Visible)
                                {
                                    this.DetailReportQQSChartBK.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportQQSChart.Visible = false;
                            }
                            if (oContentSelection.QQSOverView)
                            {
                                if (!this.InsertQQSTimeSeriesSubReport(ref aHiddenElements, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (this.DetailReportQQSOverView.Visible)
                                {
                                    this.DetailReportQQSOverView.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportQQSOverView.Visible = false;
                            }
                            if (oContentSelection.QQSStatement)
                            {
                                int num6 = 0;
                                if (!this.InsertQQSStatementSubReport(FactorType.HK, this.DetailReportQQSStatementHK, this.DetailQQSStatementHK, ref num6, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertQQSStatementSubReport(FactorType.SK, this.DetailReportQQSStatementSK, this.DetailQQSStatementSK, ref num6, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (!this.InsertQQSStatementSubReport(FactorType.BK, this.DetailReportQQSStatementBK, this.DetailQQSStatementBK, ref num6, ref rsErr))
                                {
                                    str = str + "\n\r" + rsErr;
                                }
                                if (num6 == 0)
                                {
                                    this.DetailReportQQSStatement.Visible = false;
                                    aHiddenElements.Add("Justification Weighting");
                                }
                                else
                                {
                                    this.DetailReportQQSStatement.PageBreak = PageBreak.AfterBand;
                                    num2++;
                                }
                            }
                            else
                            {
                                this.DetailReportQQSStatement.Visible = false;
                            }
                            if (oContentSelection.QQSCommentary)
                            {
                                if (RootData.Intance != null)
                                {
                                    if ((RootData.Intance.BankAmpelStep5 != AmpelType.UNKNOWN) || ((RootData.Intance.BankCommentStep5 != null) && (RootData.Intance.BankCommentStep5 != string.Empty)))
                                    {
                                        this.ampelControlQQSCommentary.DisplayStatus = RootData.Intance.BankAmpelStep5;
                                        this.cellQQSCommentary.Text = RootData.Intance.BankCommentStep5;
                                        this.DetailReportQQSCommentary.PageBreak = PageBreak.AfterBand;
                                        num2++;
                                    }
                                    else
                                    {
                                        this.DetailReportQQSCommentary.Visible = false;
                                        aHiddenElements.Add("Comment Weighting");
                                    }
                                }
                            }
                            else
                            {
                                this.DetailReportQQSCommentary.Visible = false;
                            }
                        }
                        else
                        {
                            this.DetailReportQQSAppraisal.Visible = false;
                        }
                    }
                    else
                    {
                        this.DetailReportAppendix.Visible = false;
                    }
                }
                if (num2 == 0)
                {
                    base.Visible = false;
                }
                rsErr = str;
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.CreateReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        
        private PeriodList GetPeriodList(ref string rsErr)
        {
            PeriodList list = null;
            //Todo
            //int num = -1;
            //int num2 = -1;
            //try
            //{
            //    if (RootData.Intance == null)
            //    {
            //        return list;
            //    }
            //    for (int i = 0; i < RootData.Intance.Periods.Count; i++)
            //    {
            //        if (RootData.Intance.ID == ((Period) RootData.Intance.Periods[i]).ID)
            //        {
            //            num2 = i;
            //            num = ((i - 2) < 0) ? 0 : (i - 2);
            //            break;
            //        }
            //    }
            //    if ((num == -1) || (num2 == -1))
            //    {
            //        return list;
            //    }
            //    list = new PeriodList();
            //    for (int j = num; j < (num2 + 1); j++)
            //    {
            //        list.Add((Period) RootData.Intance.Periods[j]);
            //    }
            //}
            //catch (Exception exception)
            //{
            //    rsErr = "Fehler in EndReport.GetPeriodList:" + exception.Message;
            //    Log.LogException(exception);
            //}
            return list;
        }
    

        private bool InsertActionSubReport(ref System.Collections.Specialized.StringCollection aHiddenElements, ref string rsErr)
        {
            bool flag = true;
            bool bActions = false;
            try
            {
                ActionSubReport report = new ActionSubReport();
                flag = report.CreateReport(ref bActions);
                if (flag && bActions)
                {
                    this.AddSubReportToBand(this.DetailActionList, 0, 0).ReportSource = report;
                    return flag;
                }
                this.DetailReportActionList.Visible = false;
                aHiddenElements.Add("Measures overview");
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertActionSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertBarChartImportanceSubReport(ref int iNumberOfElements, ref System.Collections.Specialized.StringCollection aHiddenElements, ref string sErr)
        {
            bool flag = true;
            bool bHasInterpretation = true;
            try
            {
                BarChartImportanceSubReport report = new BarChartImportanceSubReport();
                flag = report.CreateReport(null, ref iNumberOfElements);
                if (!flag)
                {
                    return flag;
                }
                bHasInterpretation = ReportTemplate.StringHasValue(RootData.Intance.InterpretationImportanceChart);
                if (ReportTemplate.ChartReportIsToAdd(iNumberOfElements, bHasInterpretation))
                {
                    report.Interpretation = RootData.Intance.InterpretationImportanceChart;
                    this.AddSubReportToBand(this.DetailImportanceChart, 0, 0).ReportSource = report;
                    return flag;
                }
                this.DetailReportImportanceChart.Visible = false;
                aHiddenElements.Add(ReportTemplate.s_sBarChartImportance);
            }
            catch (Exception exception)
            {
                flag = false;
                sErr = "Fehler in EndReport.InsertBarChartImportanceSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertBarChartQQSSubReport(FactorType eEFType, Band oReportBand, Band oDetailBand, ref int iNumberOfElements, ref System.Collections.Specialized.StringCollection aHiddenElements, ref string sErr)
        {
            bool flag = true;
            bool bHasInterpretation = true;
            try
            {
                BarChartQQSSubReport report = new BarChartQQSSubReport {
                    EFType = eEFType
                };
                flag = report.CreateReport(null, ref iNumberOfElements);
                if (!flag)
                {
                    return flag;
                }
                string sInput = string.Empty;
                string str2 = string.Empty;
                switch (eEFType)
                {
                    case FactorType.HK:
                        sInput = RootData.Intance.InterpretationQQSBarChartHK;
                        str2 = ReportTemplate.s_sBarChartQQS + " (HK)";
                        break;

                    case FactorType.SK:
                        sInput = RootData.Intance.InterpretationQQSBarChartSK;
                        str2 = ReportTemplate.s_sBarChartQQS + " (SK)";
                        break;

                    case FactorType.BK:
                        sInput = RootData.Intance.InterpretationQQSBarChartBK;
                        str2 = ReportTemplate.s_sBarChartQQS + " (BK)";
                        break;
                }
                bHasInterpretation = ReportTemplate.StringHasValue(sInput);
                if (ReportTemplate.ChartReportIsToAdd(iNumberOfElements, bHasInterpretation))
                {
                    report.Interpretation = sInput;
                    this.AddSubReportToBand(oDetailBand, 0, 0).ReportSource = report;
                    return flag;
                }
                oReportBand.Visible = false;
                aHiddenElements.Add(str2);
            }
            catch (Exception exception)
            {
                flag = false;
                sErr = "Fehler in EndReport.InsertBarChartQQSSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertFactorSubReport(FactorType eFactorType, Band oReportBand, Band oDetailBand, ref int iCountElements, ref string rsErr)
        {
            bool flag = true;
            bool bFactors = false;
            try
            {
                FactorSubReport report = new FactorSubReport {
                    EFType = eFactorType
                };
                flag = report.CreateReport(ref bFactors);
                if (flag && bFactors)
                {
                    this.AddSubReportToBand(oDetailBand, 0, 0).ReportSource = report;
                    iCountElements++;
                    return flag;
                }
                oReportBand.Visible = false;
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertFactorSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertImportanceStatementSubReport(FactorType eFactorType, Band oReportBand, Band oDetailBand, ref int iCountElements, ref string rsErr)
        {
            bool flag = true;
            bool bFactors = true;

            try
            {
                ImportanceStatementSubReport report = new ImportanceStatementSubReport();
                flag = report.CreateReport(eFactorType, ref bFactors);
                if (flag && bFactors)
                {
                    this.AddSubReportToBand(oDetailBand, 0, 0).ReportSource = report;
                    iCountElements++;
                    return flag;
                }
                oReportBand.Visible = false;
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertImportanceStatementSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertImportanceTimeSeriesSubReport(ref System.Collections.Specialized.StringCollection aHiddenElements, ref string rsErr)
        {
            bool flag = true;
            bool bFactors = false;
            try
            {
                ImportanceTimeSeriesSubReport report = new ImportanceTimeSeriesSubReport {
                    TimeLinePeriods = this.GetPeriodList(ref rsErr)
                };
                flag = report.CreateReport(ref bFactors);
                if (flag && bFactors)
                {
                    this.AddSubReportToBand(this.DetailImportanceOverView, 0, 0).ReportSource = report;
                    return flag;
                }
                this.DetailReportImportanceOverView.Visible = false;
                aHiddenElements.Add("Success Factor with weighting");
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertImportanceTimeSeriesSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertPotentialPortfolioSubReport(ref int iNumberOfElements, ref System.Collections.Specialized.StringCollection aHiddenElements, ref string sErr)
        {
            bool flag = true;
            bool bHasInterpretation = true;
            try
            {
                PotentialPortfolioChartSubReport report = new PotentialPortfolioChartSubReport();
                flag = report.CreateReport(null, ref iNumberOfElements);
                if (!flag)
                {
                    return flag;
                }
                bHasInterpretation = ReportTemplate.StringHasValue(RootData.Intance.InterpretationPotentialPortfolio);
                if (ReportTemplate.ChartReportIsToAdd(iNumberOfElements, bHasInterpretation))
                {
                    report.Interpretation = RootData.Intance.InterpretationPotentialPortfolio;
                    this.AddSubReportToBand(this.DetailPotentialPortfolioChart, 0, 0).ReportSource = report;
                    return flag;
                }
                this.DetailReportPotentialPortfolioChart.Visible = false;
                aHiddenElements.Add(ReportTemplate.s_sPotentialPortfolioChart);
            }
            catch (Exception exception)
            {
                flag = false;
                sErr = "Fehler in EndReport.InsertPotentialPortfolioSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertQQSStatementSubReport(FactorType eFactorType, Band oReportBand, Band oDetailBand, ref int iCountElements, ref string rsErr)
        {
            bool flag = true;
            bool bFactors = true;
            try
            {
                QQSStatementSubReport report = new QQSStatementSubReport();
                flag = report.CreateReport(eFactorType, ref bFactors);
                if (flag && bFactors)
                {
                    this.AddSubReportToBand(oDetailBand, 0, 0).ReportSource = report;
                    iCountElements++;
                    return flag;
                }
                oReportBand.Visible = false;
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertQQSStatementSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertQQSTimeSeriesSubReport(ref System.Collections.Specialized.StringCollection aHiddenElements, ref string rsErr)
        {
            bool flag = true;
            bool bFactors = false;
            try
            {
                QQSTimeSeriesSubReport report = new QQSTimeSeriesSubReport
                {
                    TimeLinePeriods = this.GetPeriodList(ref rsErr)
                };
                flag = report.CreateReport(ref bFactors);
                if (flag && bFactors)
                {
                    this.AddSubReportToBand(this.DetailQQSOverView, 0, 0).ReportSource = report;
                    return flag;
                }
                this.DetailReportQQSOverView.Visible = false;
                aHiddenElements.Add("Overview assessment in time series");
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertQQSTimeSeriesSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool InsertQuestionAnswerSubReport(int iStep, int iPart, ref System.Collections.Specialized.StringCollection aHiddenElements, ref string rsErr)
        {
            bool flag = true;
            bool bQuestionsAndAnswers = false;
            try
            {
                QuestionAnswerSubReport report = new QuestionAnswerSubReport();
                flag = report.CreateReport(iStep, iPart, ref bQuestionsAndAnswers);
                if (!flag)
                {
                    return flag;
                }
                Band oDetailBand = null;
                Band detailReportMarketSituation = null;
                string str = string.Empty;
                switch (iStep)
                {
                    case 1:
                        if (iPart == 1)
                        {
                            oDetailBand = this.DetailBusinessModel;
                            detailReportMarketSituation = this.DetailReportBusinessModel;
                            str = "Business Model ";
                        }
                        goto Label_00D0;

                    case 2:
                        switch (iPart)
                        {
                            case 2:
                                goto Label_009A;
                        }
                        goto Label_00D0;

                    case 3:
                        if (iPart == 1)
                        {
                            oDetailBand = this.DetailBusinessPlan;
                            detailReportMarketSituation = this.DetailReportBusinessPlan;
                            str = "Business strategy";
                        }
                        goto Label_00D0;

                    default:
                        goto Label_00D0;
                }
                oDetailBand = this.DetailMarketSituation;
                detailReportMarketSituation = this.DetailReportMarketSituation;
                str = "Market Situation";
                goto Label_00D0;
            Label_009A:
                oDetailBand = this.DetailEnvironmentFactor;
                detailReportMarketSituation = this.DetailReportEnvironmentFactor;
                str = "Market Situation";
            Label_00D0:
                if (bQuestionsAndAnswers)
                {
                    if (oDetailBand != null)
                    {
                        this.AddSubReportToBand(oDetailBand, 0, 0).ReportSource = report;
                    }
                    return flag;
                }
                detailReportMarketSituation.Visible = false;
                aHiddenElements.Add(str);
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InsertQuestionAnswerSubReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool SetHeaderFooter(ref string rsErr)
        {
            bool flag = true;
            try
            {
                base.Name = this.Title;
                if (RootData.Intance == null)
                {
                    return flag;
                }
                this.cellPageHeaderCompany.Text = ProjectData.Intance.CompanyName;
                this.cellPageHeaderProject.Text = ProjectData.Intance.Name;
                if (RootData.Intance != null)
                {
                    this.cellPageHeaderPeriod.Text = string.Format("{0} ({1} - {2})", ProjectData.Intance.Name, RootData.Intance.StartDate.ToShortDateString(), RootData.Intance.EndDate.ToShortDateString());
                }
                this.cellFileName.Text = "FileName: " + ProjectData.Intance.FileName;
                this.cellCreator.Text = "CreateBy: " + ProjectData.Intance.Author;
            }
            catch (Exception exception)
            {
                flag = false;
                rsErr = "Fehler in EndReport.InitReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        public string Title
        {
            get
            {
                return this.m_sTitle;
            }
            set
            {
                this.m_sTitle = value;
                this.cellPageHeaderTitel.Text = this.m_sTitle;
            }
        }            
    }
}
